package net.caidingke.shepherd.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author bowen
 */
@Configuration
@DubboComponentScan(basePackages = "net.caidingke.shepherd")
public class DubboConfiguration {

    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("shepherd-privider");
        return applicationConfig;
    }

    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://localhost:2181");
        registryConfig.setClient("zkclient");
        registryConfig.setTimeout(30000);
        return registryConfig;
    }

    @Bean
    public ProtocolConfig protocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(-1);
        protocolConfig.setThreads(200);
        protocolConfig.setSerialization("kryo");
        return protocolConfig;
    }

    @Bean
    public ServiceConfig serviceConfig() {
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setProtocol(protocolConfig());
        serviceConfig.setRegistry(registryConfig());
        serviceConfig.setApplication(applicationConfig());
        return serviceConfig;
    }
}
